<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script type="text/javascript">
    /*消耗品自动补全*/
    autoCompleteExpPrice("expNameId");
    function autoCompleteExpPrice(inputId){
        var url="${ctx}/csm/expInfo/autoComplete?expDict.expCode=${expPrice.expInfo.expDict.expCode}";
        autoComplete(inputId,url,
            function(data){
                var rows = [];
                for(var i=0; i<data.length; i++){
                    rows[rows.length] = {
                        data:data[i],
                        value:data[i].id,
                        result:data[i].expDict.expName
                    };
                }
                return rows;
            },function(data, i, max){
                if($.trim(data.expDict.expModel) != '' && null != data.expDict.expModel && typeof(data.expDict.expModel) != 'undefined'){
                    return data.expDict.expName+"|"+data.expDict.expCode+"|"+data.packageSpec+"|" + '|' + data.expDict.expModel + '|' +data.expSupplierCata.supplierJc;
                }else{
                    return data.expDict.expName+"|"+data.expDict.expCode+"|"+data.packageSpec+"|"+data.expSupplierCata.supplierName;
                }
            },function(event,data,formatted){
//                var list = $("contentTable tr").find("td:eq(0)");
//                console.log(list.length);
//                for(var i = 0; i < list.length; i++){
//                    data=jQuery.parseJSON(list[i].innerText);
//                    console.log(data);
//                }
//                console.log(data);
                $('#expInfoId').attr('value',data.id);
                $('#expDictId').attr('value',data.expDict.id);
                $('#packageSpec').attr('value',data.packageSpec);
                var select = document.getElementById("units");
                for(var i=0; i<select.options.length; i++){
                    if(select.options[i].value == data.packageUnit){
                        select.options[i].selected = true;
                        break;
                    }
                }
            })
    }

    //根据输入的批发价和价格比例计算零售价
    function updateTradePrice() {
        var tradePrice = $('#tradePrice').val();
        var priceRatio = $('#pricdRatio').val();
        var a = document.getElementById("priceRatio");
        var priceRatio = a.options[a.selectedIndex].value;
        var retailPrice = tradePrice * priceRatio;
        $('#retailPrice').val(retailPrice.toFixed(4));
    }
</script>
<div class="content-wrap">
        <div class="wrapper" style="bottom: 50px;">
            <ul class="nav nav-tabs">
                <li>
                    <a href="#"  onclick="loadDiv('priceRightDiv','${ctx}/csm/expPrice/index?expInfo.expDict.expCode=${expPrice.expInfo.expDict.expCode}')">消耗品价格列表</a>
                </li>
                <li class="active">
                    <a href="#" onclick="loadDiv('priceRightDiv','${ctx}/csm/expPrice/form?expInfo.expDict.expCode=${expPrice.expInfo.expDict.expCode}')">
                        <c:choose>
                            <c:when test="${expPrice.id==''|| expPrice.id==null}">
                                消耗品价格添加
                            </c:when>
                            <c:otherwise>消耗品价格修改</c:otherwise>
                        </c:choose>
                    </a>
                </li>
            </ul>
            <section class="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-12">
                        <form:form id="inputForm" data-parsley-validate="" modelAttribute="expPrice" onsubmit="return formSaveLoad('priceRightDiv','inputForm','${ctx}/csm/expPrice/save','${ctx}/csm/expPrice/index?expInfo.expDict.expCode=${expPrice.expInfo.expDict.expCode}');" method="post" class="form-horizontal">
                            <form:hidden path="id"/>
                            <form:hidden path="priceList.id"/>
                            <form:hidden path="expInfo.id" id="expInfoId"/>
                            <form:hidden path="expInfo.expDict.id" id="expDictId"/>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">消耗品信息：</label>
                                    <div class="col-sm-7">
                                        <form:input path="expInfo.expDict.expName" id="expNameId" htmlEscape="false" class="form-control" data-parsley-required="true"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">规格：</label>
                                    <div class="col-sm-7">
                                        <form:input path="packageSpec" id="packageSpec" htmlEscape="false" class="form-control"  maxlength="20" readonly="true" data-parsley-required="true"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">单位：</label>
                                    <div class="col-sm-7">
                                        <%--<form:input path="units" id="units" htmlEscape="false" class="form-control"  maxlength="2" readonly="true"/>--%>
                                        <form:select path="units" id="units" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('SPEC_UNIT')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">批发价：</label>
                                    <div class="col-sm-7">
                                        <form:input path="tradePrice" htmlEscape="false" class="form-control" data-parsley-required="true" data-parsley-twonum="1"
                                                onchange="updateTradePrice()"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">价格比例：</label>
                                    <div class="col-sm-7 control-label">
                                        <form:select path="" id="priceRatio" class="form-control" onchange="updateTradePrice()">
                                            <form:option value="" label="" />
                                            <form:options items="${fns:getDictList('PRICE_RATIO')}" itemLabel="label" itemValue="value" htmlEscape="false" />
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">零售价：</label>
                                    <div class="col-sm-7">
                                        <form:input path="retailPrice" htmlEscape="false" class="form-control" data-parsley-required="true" data-parsley-twonum="1" />
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">起用日期：</label>
                                    <div class="col-sm-7">
                                        <input name="startDate" htmlEscape="false" class="form-control Wdate" data-parsley-required="true" readonly
                                               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value='<fmt:formatDate value="${expPrice.startDate}" pattern="yyyy-MM-dd HH:mm:ss"/>' />

                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">费用分类：</label>
                                    <div class="col-sm-7">
                                        <form:select path="classOnRcpt" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('OUTP_RCPT_FEE_DICT')}" itemLabel="label" itemValue="value" htmlEscape="false" />
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">核算项目：</label>
                                    <div class="col-sm-7">
                                        <form:select path="classOnReckoning" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('RECK_ITEM_CLASS_DICT')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">会计科目：</label>
                                    <div class="col-sm-7">
                                        <form:select path="subjCode" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('TALLY_SUBJECT_DICT')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">病案首页：</label>
                                    <div class="col-sm-7">
                                        <form:select path="classOnMr" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('MR_FEE_CLASS_DICT')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">最高限价：</label>
                                    <div class="col-sm-7">
                                        <form:input path="priceMax" htmlEscape="false" class="form-control" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">备注信息：</label>
                                    <div class="col-sm-7">
                                        <form:textarea path="remarks" htmlEscape="false" class="form-control"  maxlength="1000"/>
                                    </div>
                                </div>
                            </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存">&nbsp;
                                        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="loadDiv('priceRightDiv','${ctx}/csm/expPrice/index?expInfo.expDict.expCode=${expPrice.expInfo.expDict.expCode}')">
                                </div>
                            </div>
                        </form:form>
                    </div>

                </div>
            </section>
        </div>
    </div>